package com.atwy.storage.service.Impl;

import com.atwy.storage.mapper.StorageMapper;
import com.atwy.storage.service.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StorageServiceImpl implements StorageService {

    @Autowired
    StorageMapper storageMapper;

    @Override
    public boolean deduct(String commodityCode, int count) {
        storageMapper.deduct(commodityCode, count);
        int afterCount = storageMapper.queryCountByCommodityCode(commodityCode);
        if (afterCount >= 0) {
            return true;
        }
        throw new RuntimeException("库存不足，扣除失败");
    }
}
